/// **************************************************************************************************
/// "Copyright (c) 2007 Sai Panyam, Inc.  All rights reserved."
/// **************************************************************************************************
/// Component Name   :	Punctuation, Member of System72.NTextile 
/// Description      :	Punctuation description
/// Author           :	Sai Panyam
/// Creation Date    :	November 09 2007
/// Modified Date    :              
/// Modified By      :
/// **************************************************************************************************
using System.Text.RegularExpressions;
using System72.NTextile.RegexLibrary;

namespace System72.NTextile
{
    /// <summary>
    /// 
    /// </summary>
    public class Punctuation
    {
        #region Private variables

        private readonly PunctuationType m_punctuationType;
        private string m_punctuation;

        #endregion

        #region Constructor
        /// <summary>
        /// 
        /// </summary>
        /// <param name="punctuationType"></param>
        public Punctuation(PunctuationType punctuationType)
        {
            m_punctuationType = punctuationType;
        }

        #endregion

        #region Public Properties
        /// <summary>
        /// 
        /// </summary>
        public PunctuationType PunctuationType
        {
            get { return m_punctuationType; }
        }
            
        #endregion
        
        #region Public Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="contentText"></param>
        /// <returns></returns>
        public string GetModifiedText(string contentText)
        {
            BaseRegex applicableRegex = getPunctuationRegexFactory();
            if (applicableRegex!=null)
            {
                contentText = parseContentText(applicableRegex, contentText);
            }
            return contentText;
        }

        #endregion

        #region Private Methods
        /// <summary>
        /// 
        /// </summary>
        /// <param name="applicableRegex"></param>
        /// <param name="contentText"></param>
        /// <returns></returns>
        private string parseContentText(BaseRegex applicableRegex, string contentText)
        {
            MatchCollection matches = applicableRegex.GetMatches(contentText);
            if (matches != null && matches.Count > 0)
            {
                contentText = applicableRegex.Regex.Replace(contentText, m_punctuation);
            }
            return contentText;
        }

        private BaseRegex getPunctuationRegexFactory()
        {
            BaseRegex regex = null;
            switch (m_punctuationType)
            {
                case PunctuationType.Copyright:
                    regex = new CopyrightRegex();
                    m_punctuation = "&#169;";
                    break;
                case PunctuationType.Trademark:
                    regex = new TrademarkRegex();
                    m_punctuation = "&#8482;";
                    break;
                case PunctuationType.Registered:
                    regex = new RegisteredRegex();
                    m_punctuation = "&#174;";
                    break;
                case PunctuationType.EmDash:
                    regex = new EmDashRegex();
                    m_punctuation = "&#8212;";
                    break;
                case PunctuationType.EnDash:
                    regex = new EnDashRegex();
                    m_punctuation = "&#8211;";
                    break;
                case PunctuationType.Dimension:
                    regex = new DimensionRegex();
                    m_punctuation = "&#215;";
                    break;
                case PunctuationType.OpenSingleQuote:
                    regex = new OpenSingleQuoteRegex();
                    m_punctuation = "&#8216;";
                    break;
                case PunctuationType.CloseSingleQuote:
                    regex = new CloseSingleQuoteRegex();
                    m_punctuation = "&#8217;";
                    break;
                case PunctuationType.OpenDoubleQuote:
                    regex = new OpenDoubleQuoteRegex();
                    m_punctuation = "&#8220;";
                    break;
                case PunctuationType.CloseDoubleQuote:
                    regex = new CloseDoubleQuoteRegex();
                    m_punctuation = "&#8221;";
                    break;
                case PunctuationType.Ellipses:
                    regex = new EllipsesRegex();
                    m_punctuation = "&#8230;";
                    break;
                
            }
            return regex;
        }

        #endregion
    }
}
